/*
 * Copyright (c) 2022  by Junzhao
 * THIS FILE IS PART OF JAVASE Song Huongkang PROJECT
 * All Rights Reserved.
 */

package 手动处理;

import 自定义异常.MyException;

/**
 * @description
 * @author 俊昭
 * @date 2022/4/11
*/
public class ThrowTest {
    public static void main(String[] args) throws Exception {
        Student s = new Student();

        s.regist(5);
//        System.out.println(s.getId());
        System.out.println(s.toString());
        s.regist(-1);
    }
}
class Student{
    private int id;

    public void regist(int id) throws Exception {
        if (id > 0){
            this.id = id;
        }else{
//            System.out.println("您输入的数据非法");
//            throw new RuntimeException("您输入的数据非法!");
//            throw new Exception("您输入的数据非法!");
            throw new MyException("不能输入负数");
        }
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                '}';
    }

    public int getId() {
        return id;
    }
}